package com.anyi.gulimall.ware.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.anyi.gulimall.ware.vo.PurchaseDoneVo;
import com.anyi.gulimall.ware.vo.PurchaseMergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.anyi.gulimall.ware.entity.WmsPurchaseEntity;
import com.anyi.gulimall.ware.service.WmsPurchaseService;
import com.anyi.gulimall.common.utils.PageUtils;
import com.anyi.gulimall.common.utils.R;



/**
 * 采购信息
 *
 * @author anyi
 * @email 1961741003@qq.com
 * @date 2022-07-27 12:29:35
 */
@RestController
@RequestMapping("ware/purchase")
public class WmsPurchaseController {
    @Autowired
    private WmsPurchaseService wmsPurchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("ware:wmspurchase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wmsPurchaseService.queryPage(params);

        return R.ok().put("page", page);
    }

    // /ware/purchase/done
    /**
     * 查询未领取的采购单
     * @return
     */
    @PostMapping("/done")
    // @RequiresPermissions("ware:wmspurchase:list")
    public R done(@RequestBody PurchaseDoneVo purchaseDoneVo){
        wmsPurchaseService.donePurchase(purchaseDoneVo);
        return R.ok();
    }


    /**
     * 查询未领取的采购单
     * @return
     */
    @GetMapping("/unreceive/list")
    // @RequiresPermissions("ware:wmspurchase:list")
    public R unReceive(@RequestParam Map<String, Object> params){
        PageUtils page = wmsPurchaseService.getUnReceive(params);

        return R.ok().put("page", page);
    }

    /**
     * 将需求项合并成需求单
     */
    @RequestMapping("/merge")
    // @RequiresPermissions("ware:wmspurchase:list")
    public R merge(@RequestBody PurchaseMergeVo purchaseMergeVo){
        wmsPurchaseService.merge(purchaseMergeVo);
        return R.ok();
    }

    // /ware/purchase/received
    @RequestMapping("/received")
    // @RequiresPermissions("ware:wmspurchase:list")
    public R received(@RequestBody List<Long> ids){
        wmsPurchaseService.received(ids);
        return R.ok();
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("ware:wmspurchase:info")
    public R info(@PathVariable("id") Long id){
		WmsPurchaseEntity wmsPurchase = wmsPurchaseService.getById(id);

        return R.ok().put("wmsPurchase", wmsPurchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("ware:wmspurchase:save")
    public R save(@RequestBody WmsPurchaseEntity wmsPurchase){
        wmsPurchase.setCreateTime(new Date());
        wmsPurchase.setUpdateTime(new Date());
		wmsPurchaseService.save(wmsPurchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("ware:wmspurchase:update")
    public R update(@RequestBody WmsPurchaseEntity wmsPurchase){
        wmsPurchase.setUpdateTime(new Date());
		wmsPurchaseService.updateById(wmsPurchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("ware:wmspurchase:delete")
    public R delete(@RequestBody Long[] ids){
		wmsPurchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
